<?php
namespace WeChat;
use Swiftx\Base\Object;

/**
 * ---------------------------------------------------------------------------------------------------------------------
 * OAuth
 * ---------------------------------------------------------------------------------------------------------------------
 * @author		胡永强  <odaytudio@gmail.com>
 * @since		2015-12-15
 * @copyright	Copyright (c) 2014-2015 Swiftx Inc.
 * ---------------------------------------------------------------------------------------------------------------------
 * @property-read string $OpenID        用户唯一标识
 * @property-read string $AccessToken   网页授权接口调用凭证
 * @property-read int $Expires          凭证有效时间
 * @property-read int $RefreshToken     用户刷新access_token
 * @property-read int $OverTime         凭证超时时间
 * @property-read array $Scope          用户授权的作用域
 * ---------------------------------------------------------------------------------------------------------------------
 */
class OAuth extends Object {

    /** @var string  */
    protected $_open_id;
    /** @var string  */
    protected $_access_token;
    /** @var string  */
    protected $_refresh_token;
    /** @var int  */
    protected $_expires;
    /** @var int  */
    protected $_create_time;
    /** @var array  */
    protected $_scope;

    /**
     * 创建OAuth对象
     * @param string $open_id
     * @param int $expires
     * @param string $access_token
     * @param string $refresh_token
     * @param array $scope
     */
    public function __construct($open_id, $expires, $access_token, $refresh_token, array $scope){
        $this->_open_id = $open_id;
        $this->_access_token = $access_token;
        $this->_refresh_token = $refresh_token;
        $this->_scope = $scope;
        $this->_expires = $expires;
        $this->_create_time = time();
    }

    /**
     * 获取OpenID
     * @return string
     */
    protected function _getOpenID(){
        return $this->_open_id;
    }

    /**
     * AccessToken
     * @return string
     */
    protected function _getAccessToken(){
        return $this->_access_token;
    }

    /**
     * RefreshToken
     * @return string
     */
    protected function _getRefreshToken(){
        return $this->_refresh_token;
    }

    /**
     * 用户授权的作用域
     * @return array
     */
    protected function _getScope(){
        return $this->Scope;
    }

    /**
     * 有效时间
     * @return int
     */
    protected function _getExpires(){
       return $this->_expires;
    }

    /**
     * 创建时间
     * @return int
     */
    protected function _getCreateTime(){
        return $this->_create_time;
    }

    /**
     * 过期时间
     * @return int
     */
    protected function _getOverTime(){
        return $this->_create_time+$this->_expires;
    }

}
